package com.ssmTest.controller;

import com.ssmTest.model.SecondHand;
import com.ssmTest.service.ISecondHandService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class SecondInformationController {
    @Resource
    private ISecondHandService iSecondHandService;

    //返回审核列表
    @RequestMapping("/secondInformation")
    public String selectUser(HttpSession session, ModelMap modelMap) {
        List<SecondHand> list = null;
        list = iSecondHandService.SecondHandList(0);
        modelMap.addAttribute("list", list);
        return "secondeInformation";
    }

    //审核成功
    @RequestMapping("/secondInformationSuccess.do")
    public String selectsuccessUser(HttpSession session, int id, ModelMap modelMap) {
        SecondHand secondHand=iSecondHandService.selectSecondHand(id);
        secondHand.setToexamine(1);
        iSecondHandService.updateInformation(secondHand);
        List<SecondHand> list = null;
        list=iSecondHandService.SecondHandList(0);
        modelMap.addAttribute("list",list);
        return "secondeInformation";
    }


    //审核失败
    @RequestMapping("/secondInformationFail.do")
    public String selectfailUser(HttpSession session, String reasion, ModelMap modelMap) {
        System.out.println(reasion+"  "+session.getAttribute("sid"));
        SecondHand secondHand=iSecondHandService.selectSecondHand(Integer.parseInt(session.getAttribute("sid").toString()));
        secondHand.setFail_reasion(reasion);
        secondHand.setToexamine(2);
        iSecondHandService.updateInformation(secondHand);
        return "success";
    }

    //二手信息弹出界面
    @RequestMapping("/secondnReasionPage.do")
    public  String secondnReasionPage(ModelMap modelMap,int id,HttpSession session){
        session.setAttribute("sid",id);
        modelMap.addAttribute("id",id);
        modelMap.addAttribute("url","secondInformationFail.do");
        return "writeReasionPage";
    }

}
